<?php

namespace app\company\model;


use Exception;
use think\Model;

/**
 * @property int $id
 * @property string $name
 * @property string $address
 * @property string $mobile
 * @property int $company_id 公司ID
 */
class Warehouse extends Base
{


    public static function onBeforeInsert(Warehouse $model): void
    {
        $model->company_id = getCompanyId();
    }

    /**
     * @param Warehouse $model
     * @return void
     * @throws Exception
     */
    public static function onBeforeDelete(Warehouse $model): void
    {
        if ($model->companyOrderStorages()->sum('quantity') > 0) exception('删除失败，该仓库下存在商品');
        if ($model->warehouseAreas()->count() > 0) $model->warehouseAreas->delete();//删除仓库区域
        //删除库位... 此动作在$model->warehouseAreas->delete() 事件中完成
    }

}